/**
 * 
 */
package edu.umd.clip.lm.model.data;

import edu.umd.clip.lm.util.Long2IntMap;

/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public class MaskedFuturesTrainingDataFilter implements TrainingDataFilter {
	private final long mask;
	
	public MaskedFuturesTrainingDataFilter(long overtMask) {
		this.mask = overtMask;
	}

	/* (non-Javadoc)
	 * @see edu.umd.clip.lm.model.training.TrainingDataFilter#filterData(edu.umd.clip.lm.model.training.ContextFuturesPair)
	 */
	@Override
	public ContextFuturesPair filterData(ContextFuturesPair pair) {
		Long2IntMap factorsCounts = new Long2IntMap(pair.getFutures().length);
		
		for(TupleCountPair tcp : pair.getFutures()) {
			factorsCounts.addAndGet(tcp.tuple & mask, tcp.count);
		}
		
		TupleCountPair newFutures[] = TupleCountPair.fromMap(factorsCounts);
		return new ContextFuturesPair(pair.getContext(), newFutures);
	}

}
